package com.liuyan.service.impl;

import com.liuyan.dao.IUserDao;
import com.liuyan.pojo.User;
import com.liuyan.service.IUserService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/* *
 * 用户类
 * Created by HZC on 2015/10/6.
 */
@Service("iUserService")
@Transactional
public class UserServiceImpl implements IUserService {

    private static Logger log = Logger.getLogger(UserServiceImpl.class);
    @Resource
    private IUserDao userDao;


    public User getUserById(int userId) {
        // TODO Auto-generated method stub
        return this.userDao.selectByPrimaryKey(userId);
    }

    /**
     * 用户登录
     * @param userName
     * @param password
     * @return
     */
    @Override
    public boolean getUserPass(String userName,String password) {

        User user = this.userDao.getUserPass(userName,password);
        if(user == null){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public boolean addUser(User user) {
        int userId = 0;
           userId = this.userDao.addUser(user);
        return true;
    }

    /**
     * 用户名是否已经存在
     * @param userName
     * @return
     */
    @Override
    public boolean isHave(String userName) {

        User user = this.userDao.isHave(userName);
        if(user == null){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public User getUser(String userName) {
        User user = this.userDao.getUser(userName);
        return user;
    }

    @Override
    public boolean modifyPassword(User user) {
        int i = 0;
        i = this.userDao.modifyPassword(user);
        return (i>0)?true:false;
    }

    @Override
    public boolean modifyHead(User user) {
        int i = 0;
        i = this.userDao.modifyHead(user);
        return (i>0)?true:false;
    }

    @Override
    public List<User> getUserList() {
        return this.userDao.getUserList();
    }

    @Override
    public boolean getPwdCheck(User user) {
        User user1 = this.userDao.getPwdCheck(user);
        return (user1!=null)?true:false;
    }


}